<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('flink任务配置列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>任务名称：</label>
                                <input type="text" name="jobName"/>
                            </li>
                            <li>
                                <label>提交模式：</label>
                                <select name="deployMode"
									th:with="type=${@dict.getType('flink-config-deployMode')}">
										<option value="">所有</option>
										<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
											th:value="${dict.dictValue}"></option>
								</select>
                            </li>
                            <li>
                                <label>运行后的任务id：</label>
                                <input type="text" name="jobId"/>
                            </li>
                            <li>
                                <label>是否开启：</label>
                                <select name="isOpen"
									th:with="type=${@dict.getType('flink-config-isOpen')}">
										<option value="">所有</option>
										<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
											th:value="${dict.dictValue}"></option>
								</select>
                            </li>
                            <li>
                                <label>任务状态：</label>
                                <select name="status"
									th:with="type=${@dict.getType('flink-config-status')}">
										<option value="">所有</option>
										<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
											th:value="${dict.dictValue}"></option>
								</select>
                            </li>
                            <li class="select-time">
                                <label>最后一次启动时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginLastStartTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endLastStartTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="flink:config:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="flink:config:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('flink:config:edit')}]];
        var removeFlag = [[${@permission.hasPermi('flink:config:remove')}]];
        var deployModes = [[${@dict.getType('flink-config-deployMode')}]];
        var stats = [[${@dict.getType('flink-config-status')}]];
        var prefix = ctx + "flink/config";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "flink任务配置",
                columns: [{
                    checkbox: true
                },
                /* {
                    field: 'id', 
                    title: '更新版本号 用于乐观锁',
                    visible: false
                }, */
                {
                    field: 'jobName', 
                    title: '任务名称'
                },
                {
                    field: 'deployMode', 
                    title: '提交模式',
		        	formatter: function (value, row, index) {
		        		return $.table.selectDictLabel(deployModes, value);
		        	}
                },
                {
                    field: 'flinkRunConfig', 
                    title: 'flink运行配置'
                },
                {
                    field: 'flinkSql', 
                    title: 'sql语句'
                },
                {
                    field: 'flinkCheckpointConfig', 
                    title: 'checkPoint配置'
                },
                {
                    field: 'jobId', 
                    title: '运行后的任务id'
                },
                {
                    field: 'isOpen', 
                    title: '是否开启',
		        	formatter: function (value, row, index) {
		        		return isOpenTools(row);
		        	}
                },
                {
                    field: 'status', 
                    title: '任务状态',
		        	formatter: function (value, row, index) {
		        		return $.table.selectDictLabel(stats, value);
		        	}
                },
                {
                    field: 'extJarPath', 
                    title: 'udf地址'
                },
                {
                    field: 'lastStartTime', 
                    title: '最后一次启动时间'
                },
                {
                    field: 'lastRunLogId', 
                    title: '最后一次日志'
                },
                {
                    field: 'version', 
                    title: '版本号'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
		/* 是否开启显示 */
		function isOpenTools(row) {
		    if (row.isOpen == 0) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" ></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" )"></i> ';
    		}
		}
    </script>
</body>
</html>